#!/bin/sh

# 编译C源代码
if [ -f /usr/lib/netflow/src/bandwidth_manager.c ]; then
    gcc -o /usr/lib/netflow/bin/bandwidth_manager /usr/lib/netflow/src/bandwidth_manager.c -lm -lpthread
    echo "Compiled bandwidth_manager"
fi

if [ -f /usr/lib/netflow/src/priority_scheduler.c ]; then
    gcc -o /usr/lib/netflow/bin/priority_scheduler /usr/lib/netflow/src/priority_scheduler.c -lm -lpthread
    echo "Compiled priority_scheduler"
fi

# 设置启动脚本权限
if [ -f /etc/init.d/netflow ]; then
    chmod +x /etc/init.d/netflow
    echo "Set permissions for init script"
fi

# 启用NetFlow服务
if [ -f /etc/init.d/netflow ]; then
    /etc/init.d/netflow enable
    echo "Enabled NetFlow service"
fi

# 执行CMD
exec "$@"
